package com.glorysoft.hlgdpda.ui.materialandtool.viewmodel

import com.glorysoft.hlgdpda.base.BaseViewModel
import com.glorysoft.hlgdpda.entity.ui.CallObserveBean
import com.glorysoft.hlgdpda.model.TaskRepository
import com.google.gson.JsonObject

/**
 * FileName: CarrierReplaceViewModel
 * Author: XJH
 * Date: 2021/8/20 15:42
 * Description:
 * History:
 */
class CarrierReplaceViewModel : BaseViewModel() {

    private val carrierRepository = TaskRepository()


    fun replaceCarrier(carrier: String, lot: String, newCarrier: String) {
        //先解绑再绑定
        val map = JsonObject()
        map.addProperty("LOTID", lot)
        map.addProperty("CARRIERID", carrier)
        launchOnlyResult({
            carrierRepository.carrierUnBindLot(map)
            val map2 = JsonObject()
            map2.addProperty("LOTID", lot)
            map2.addProperty("CARRIERID", newCarrier)
            carrierRepository.carrierBindLot(map2)
            defUI.callObserve.value = CallObserveBean(100, "")
        })
    }

    /**
     * 获取批次信息
     */
    fun searchLotInfo(lot: String) {
        val map = JsonObject()
        map.addProperty("ACTIONTYPE", "LOTINFOBYID")
        map.addProperty("LOTID", lot)
        launchOnlyResult({
            val lotInfo = carrierRepository.getLotInfo(map)
            defUI.callObserve.value = CallObserveBean(200, lotInfo)
        })
    }

    fun searchCarrierInfo(carrier: String) {
        val map = JsonObject()
        map.addProperty("CARRIERID", carrier)
        launchOnlyResult({
            val lotInfo = carrierRepository.getLotInfoByCarrier(map)
            defUI.callObserve.value = CallObserveBean(200, lotInfo)
        })
    }

}